package com.fh.controller;


import com.baomidou.mybatisplus.core.injector.methods.SelectList;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fh.service.CustomerService;
import com.fh.service.ImagesService;
import com.fh.service.UserService;
import com.fh.service.impl.RegisterServiceImpl;
import com.utils.bean.*;
import com.utils.exception.BusinessException;
import com.utils.pulc.ResultBody;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;


/**
 *  @description 这些接口使用的不是 RESTful风格的接口
 *  使用的全是PostMapping
 *  正常的风格 增加使用Post  删除使用Del 修改使用Put 查询要使用 Get
 * @author whf
 * @date 2023年04月24日 15:15
 */
@RequestMapping("demo1")
@RestController
public class RegisterController {

    @Autowired
    private RegisterServiceImpl registerService;

    @Autowired
    private CustomerService customerService;

    @Autowired
    private ImagesService imagesService;

    /**
     * @param safety
     * @return com.fh.utils.ResultBody<java.lang.Object>
     * @description: 登录
     * @author whf
     * @date 2023/4/25 15:01
     */
    @PostMapping("index")
    public ResultBody<Safety> index(@Valid @RequestBody Safety safety) {
        return ResultBody.ok(registerService.getSafety(safety));
    }

    /**
     * @description: 密码正确就会对个人信息进行查询
     * @author whf
     * @date 2023/5/10 14:12
     * @param safety
     * @return com.utils.bean.User
     */
    @PostMapping("user")
    public ResultBody<User> getUser(@Valid @RequestBody Safety safety) {
        return ResultBody.ok(registerService.LoginJudgment(safety));
    }


    /**
     * @param user 注册接口对个人信息表表进行添加
     * @return com.fh.utils.ResultBody<java.lang.Object>
     * @description:
     * @author whf
     * @date 2023/4/25 15:02
     */
    @GlobalTransactional(rollbackFor = BusinessException.class)
    @PostMapping("setUser")
    public ResultBody<User> setUser(@Valid @RequestBody User user) {
        return ResultBody.ok(registerService.setUser(user));
    }
    /**
     * @param safety 对账号密码进行保存
     * @return com.fh.utils.ResultBody<java.lang.Object>
     * @description:
     * @author whf
     * @date 2023/4/25 15:02
     */
    @GlobalTransactional(rollbackFor = BusinessException.class)
    @PostMapping("setSafety")
    public ResultBody<Safety> setUser(@Valid @RequestBody Safety safety) {
        return ResultBody.ok(registerService.setSafety(safety));
    }

    /**
     * @param Safetyoruser 对账号密码进行保存
     * @return com.fh.utils.ResultBody<java.lang.Object>
     * @description:
     * @author whf
     * @date 2023/4/25 15:02
     */
    @GlobalTransactional(rollbackFor = BusinessException.class)
    @PostMapping("setSafetyoruser")
    public ResultBody<Safetyoruser> setSafetyoruser(@Valid @RequestBody Safetyoruser Safetyoruser) {
        registerService.setSafetyoruser(Safetyoruser);
        return ResultBody.ok();
    }

    /**
     * @description: 根据登录用户的id 查询权限
     * @author whf
     * @date 2023/4/25 15:03
     * @param substitute
     * @return com.fh.utils.ResultBody<java.lang.Object>
     */
    @PostMapping("selectAll")
    public ResultBody<List<Role>> selectAll(@RequestBody Substitute substitute) {
        return ResultBody.ok(registerService.selectUID(substitute));
    }

    /**
     * @description: 分页查询
     * @author whf
     * @date 2023/5/11 8:37
     * @param customerPage
     * @return com.utils.pulc.ResultBody<com.baomidou.mybatisplus.extension.plugins.pagination.Page<com.utils.bean.Customer>>
     */
    @PostMapping("page")
    public ResultBody<Page<Customer>> page(@RequestBody CustomerPage customerPage){
        return  ResultBody.ok(customerService.getCustomer(customerPage));
    }

    /**
     * @description: 对客户的信息进行添加
     * @author whf
     * @date 2023/5/11 14:36
     * @param customer
     * @return com.utils.pulc.ResultBody<java.lang.Object>
     */
    @PostMapping("save")
    public ResultBody<Object> save(@RequestBody Customer customer){
        customerService.save(customer);
        return ResultBody.ok();
    }


    /**
     * @description: 对他的ID进行删除
     * @author whf
     * @date 2023/5/17 9:20
     * @param
     * @return null
     */
    @PostMapping("delCostomer")
    public ResultBody<Object> delCostomer(@RequestBody CostomerID costomerID){
        customerService.delCustomer(costomerID);
        return ResultBody.ok();
    }
    /**
     * @description: 对一群人进行删除
     * @author whf
     * @date 2023/5/17 9:22
     * @param costomerIDS
     * @return com.utils.pulc.ResultBody<java.lang.Object>
     */
    @PostMapping("delCostomers")
    public ResultBody<Object> delCostomers(@RequestBody List<CostomerID> costomerIDS){
        customerService.delCustomers(costomerIDS);
        return ResultBody.ok();
    }

    /**
     * @description: 根据条件查询
     * @author whf
     * @date 2023/5/17 10:33
     * @return com.utils.pulc.ResultBody<java.util.List<com.utils.bean.Customer>>
     */
    @PostMapping("getCustomerIF")
    public ResultBody<List<Customer>> getCustomerIF(@RequestBody Customer customer){
        return ResultBody.ok(customerService.getCustomerIF(customer));
    }

    /**
     * @description: 当权限最大的人查询 得到全部的信息 包括员工
     * @author whf
     * @date 2023/5/17 14:42
     * @return com.utils.pulc.ResultBody<java.util.List<com.utils.bean.User>>
     */
    @PostMapping("getBoss")
    public ResultBody<Page<Customer>> getBoss(@Valid @RequestBody CustomerPage customerPage){
        return ResultBody.ok(customerService.getBoss(customerPage));
    }

    /**
     * @description: 对图片进行添加
     * @author whf
     * @date 2023/5/31 8:46
     * @param images
     */
    @PostMapping("setMultipartFile")
    public ResultBody<Object> setMultipartFile(@RequestBody Images images){
        imagesService.add(images);
        return ResultBody.ok();
    }

    /**
     * @description: 查询照片
     * @author whf
     * @date 2023/6/1 15:00
     * @param imagesOrUser
     * @return com.utils.pulc.ResultBody<java.util.List<com.utils.bean.Images>>
     */
    @PostMapping("getImages")
    public ResultBody<List<Images>> getImage(@RequestBody ImagesOrUser imagesOrUser){
        return ResultBody.ok(imagesService.getImages(imagesOrUser));
    }

    /**
     * @description: 对图片进行删除
     * @author whf
     * @date 2023/6/1 17:23
     * @param imagesUpdate
     * @return com.utils.pulc.ResultBody<java.lang.Object>
     */
    @PostMapping("updateImages")
    public ResultBody<Object> updateImages(@RequestBody ImagesUpdate imagesUpdate){
        imagesService.updateImages(imagesUpdate);
        return ResultBody.ok();
    }

    @Autowired
    private UserService userService;
    @PostMapping("updateMoney")
    public ResultBody<Object> updateMoney(@RequestBody Money money){
        userService.updateMoney(money);
        return ResultBody.ok();
    }

}
